const app = getApp();
Page({
  data: {
    isShowNoti: true,
  },
  formSubmit(e) {
    let formid = e.detail.formId
    let openid = wx.getStorageSync('openid') || wx.getStorageSync('wsOpenID') || wx.getStorageSync('OPENID')
    app.util.request({
      url:'pushService/api/formid',
      data:{
        formid,
        openid
      },
      method:'GET'
    })
    let { identityCard: identity_card = '', phone = '', userName: name = '' } = e.detail.value;
    let isPass = true;
    let hint = '';
    if (name === '') {
      hint = '请填写真实姓名';
    } else if (phone === '') {
      hint = '请填写手机号码';
    } else if (!(/^(0|86|17951)?(13[0-9]|15[012356789]|16[6]|17[12345678]|18[0-9]|14[56789]|19[89])[0-9]{8}$/.test(phone))) {
      hint = '手机号格式不正确';
    } else if (identity_card === '') {
      hint = '请填写证件号码';
    } else if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/).test(identity_card)) {
      hint = '身份证号码格式不正确';
    } else {
      isPass = false;
      app.util.request({
        url: 'entry/wxapp/user',
        data: {
          name,
          phone,
          identity_card,
          op: 'postRealName',
        },
        module: 'cm_video_alarm',
        success: res => {
          wx.showModal({
            title: '提交成功',
            showCancel: false,
            success: res => {
              app.util.navigateTo('/cm_video_alarm/index/index');
            },
          });
        },
        fail: res => {
          wx.showModal({
            title: '提交失败',
            showCancel: false,
            success: res => {
              app.util.navigateTo('/cm_video_alarm/index/index');
            },
          });
        },
      });
    }
    if (isPass) {
      wx.showModal({
        title: hint,
        showCancel: false,
      });
    }
  },
  closeNoti() {
    let { isShowNoti } = this.data;
    this.setData({
      isShowNoti: !isShowNoti,
    });
  },
});
